--埋祸于暗
local maihuoyuan = fk.CreateSkill {
    name = "mcdh_maihuoyuan",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

maihuoyuan:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and
                player.phase == Player.Finish and
                player:getMark("mcdh_maihuoyuan-turn") >= 3
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room;
        local ids = room:askForCard(player, 2, 2, true, self.name, true, ".", "#mcdh_maihuoyuan-invoke")
        if #ids > 0 then
            self.cost_data = ids
            return true
        end
        return false
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local ids = room:askForGuanxing(player, self.cost_data, { 0, 0 }, { #self.cost_data, #self.cost_data },nil,true)
        room:moveCards({
            ids = ids.bottom,
            from = player.id,
            toArea = Card.DrawPile,
            moveReason = fk.ReasonJustMove,
            skillName = self.name,
            drawPilePosition =-1,
        })
        room:drawCards(player, 3, self.name)
    end,
})

maihuoyuan:addEffect(fk.AfterCardsMove,{
    can_refresh = function(self, event, target, player, data)
        if player.phase ~= Player.NotActive then
            for _, move in ipairs(data) do
                if move.to == player.id and move.toArea == Card.PlayerHand then
                    return true
                end
            end
        end
        return false
    end,
    on_refresh = function(self, event, target, player, data)
        for _, move in ipairs(data) do
            if move.to == player.id and move.toArea == Card.PlayerHand then
                player.room:addPlayerMark(player, "mcdh_maihuoyuan-turn", #move.moveInfo)
            end
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_maihuoyuan"] = "埋祸",
    [":mcdh_maihuoyuan"] = "『埋祸于暗』<br>结束阶段，若你本回合获得过至少三张手牌，你可以将两张牌以任意顺序置于牌堆底，然后摸三张牌。",
    ["#mcdh_maihuoyuan-invoke"] = "埋祸于暗：你可以将两张牌置于牌堆底，然后摸三张牌",
}
return maihuoyuan